package com.logistics.config.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.logistics.config.entity.domain.Config;
import com.logistics.config.mapper.ConfigMapper;
import com.logistics.utils.tool.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ConfigService extends ServiceImpl<ConfigMapper, Config> {

    /**
     * 查找配置值信息
     * @param type
     * @return
     */
    public String valueByType(String type){
        Config config = this.getOne(new LambdaQueryWrapper<Config>().eq(Config::getType, type));
        if(StringUtils.isNotNull(config)){
            return config.getValue();
        }
        return null;
    }

    /**
     * 获取配置信息值
     * @param types
     * @return
     */
    public Map<String, String> valuesByType(List<String> types){
        return this.list(new LambdaQueryWrapper<Config>().in(Config::getType, types)).
                stream().collect(Collectors.toMap(Config::getType, Config::getValue));
    }
}
